#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
    long int len = 0;
    char *ch = NULL;

    FILE *fp1 = fopen("./01.yuv", "r");     // 960*540*3/2 = 777600
    FILE *fp2 = fopen("./02.yuv", "r");
    FILE *fp3 = fopen("mix.yuv", "w+");

    if (fp1 == NULL) 
        printf("open file failt...\n");

    fseek(fp1, 0, SEEK_END);
    len = ftell(fp1);
    printf("fp1 len = %ld\n", len);
    ch = (char *)malloc(sizeof(char *) * len);
    memset(ch, 0, len);

    rewind(fp1);
    fread(ch, 1, len, fp1);
    fwrite(ch, 1, len, fp3);


    ch = NULL;
    len = 0;
    fseek(fp2, 0, SEEK_END);
    len = ftell(fp2);
    printf("fp2 len = %ld\n", len);
    ch = (char *)malloc(sizeof(char *) * len);
    memset(ch, 0, len);

    rewind(fp2);
    fread(ch, 1, len, fp2);
    fwrite(ch, 1, len, fp3);

    fclose(fp1);
    fclose(fp2);
    fclose(fp3);

    return 0;
}


